package online.niuma.xiaocubao.controller;

import online.niuma.xiaocubao.common.Constants;
import online.niuma.xiaocubao.pojo.params.LoginParam;
import online.niuma.xiaocubao.pojo.params.SignUpParam;
import online.niuma.xiaocubao.pojo.vo.Result;
import online.niuma.xiaocubao.service.impl.LoginServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 一颗蛋50斤
 * IntelliJ IDEA
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Resource
    private LoginServiceImpl loginService;

    @PostMapping
    public Result login(@RequestBody LoginParam loginParam) {
        return loginService.login(loginParam);
    }


    @PostMapping("/checkSignUp")
    public Result checkSignUp(@RequestBody SignUpParam signUpParam) {
        String account = signUpParam.getAccount();
        String email = signUpParam.getEmail();
        return loginService.checkSignUp(account, email);
    }


    @PostMapping("/signUp")
    public Result signUp(@RequestBody SignUpParam signUpParam) {
        return loginService.signUp(signUpParam.getAccount(),
                signUpParam.getPassword(),
                signUpParam.getEmail(),
                signUpParam.getVerificationCode());
    }

    @PostMapping("/logout")
    public Result logout(@RequestHeader(Constants.HEAD_TOKEN) String token) {
        return loginService.logout(token);
    }

}
